package day0307;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

public class Cmd {

    public static void main(String[] args) throws IOException, InterruptedException {
        //创建ProcessBuilder对象
        ProcessBuilder pb = new ProcessBuilder("BBDown.exe", "/c", "https://www.bilibili.com/video/BV1fv4y1s7UG/?spm_id_from=333.1007.tianma.3-1-7.click&vd_source=22fda8a50aac17cd70d9c20f270f3eb8");
        //设置工作目录
        pb.directory(new File("C:\\Users\\10854\\Videos\\BBDown\\ffmpeg-2023-03-02-git-814178f926-full_build\\bin"));
        //启动进程
        Process p = pb.start();
        //读取进程的输出流
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        //打印输出结果
        String line = null;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
        //等待进程结束
        p.waitFor();
//        Runtime runtime = Runtime.getRuntime();
//
//        try {
//            Process p = runtime.exec("BBDown /c https://www.bilibili.com/video/BV1fv4y1s7UG/?spm_id_from=333.1007.tianma.3-1-7.click&vd_source=22fda8a50aac17cd70d9c20f270f3eb8");
//            //读取进程的输出流
//            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
//            //打印输出结果
//            String line = null;
//            while ((line = br.readLine()) != null) {
//                System.out.println(line);
//            }
//
//            //等待进程结束
//            p.waitFor();
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
    }
}
